<div class="content-titulo">
    <h2><?php echo $this->titulo;?></h2>
</div>
<div class="content-form">

    <form id="form" method="post" action="" enctype="application/x-www-form-urlencoded">
        <input type="hidden" id="PRO_ID" name="PRO_ID" value="<?php echo $this->data['PRO_ID']?>" />
    <div class="col">
        <div class="cnt-foto">
    <?php $imgs_pri = glob('public/upload/produto/'.$this->data['PRO_ID'].'_*_hl.*');
    if(isset($imgs_pri[0])){
    ?> 
            <img class="fot_pr" src="<?php echo $this->urlbase.'/'.$imgs_pri[0].'?a='.  rand(99, 9999); ?>" />
    <?php } ?>
        </div>
        <div class="slider">
            <ul>
            <?php $imgs_pri = glob('public/upload/produto/'.$this->data['PRO_ID'].'_*_tb.*');
            foreach($imgs_pri as $img){
            ?> 
                <li><img src="<?php echo $this->urlbase.'/'.$img.'?a='.  rand(99, 9999); ?>" class="img" /></li>
            <?php } ?>
            </ul>
        </div>    
        <div style="margin: 10px 0px; text-align: center;">
            <span class="btn btn-success fileinput-button">
                <span>carregar fotos</span>
                <input id="fileupload" type="file" name="files[]" multiple>
            </span>
            <span class="btn btn-default ex-ft">
                <span>excluir foto</span>
            </span>
            <div id="progress" class="progress" style="margin-top: 10px">
                <div class="progress-bar progress-bar-success"></div>
            </div>
        </div>
        
    </div>
    
    <div class="col">
        <dd class="titulo"><label>Código do Produto: <?php echo $this->data['PRO_ID']?></label></dd>
        <dt><label>Status</label></dt> <dd><?php echo elemform::checkbox('PRO_STA', '1', $this->data['PRO_STA']); ?> Ativo</dd>
        <dt><label>Título do Produto</label></dt> <dd><input type="text" name="PRO_NOM" value="<?php echo $this->data['PRO_NOM']?>" /></dd>
        <dt><label>Descrição do Produto</label></dt> <dd> <textarea name="PRO_DES"><?php echo $this->data['PRO_DES']?></textarea></dd>
        <dt><label>Quantidade Mínima</label></dt> <dd><input type="text" name="PRO_QTDMIN" value="<?php echo $this->data['PRO_QTDMIN']?>" class="numero" /></dd>
        <dt><label>Valor do Produto</label></dt> <dd><input type="text" name="PRO_VAL" value="<?php echo $this->data['PRO_VAL']?>" class="valor" /></dd>
        <dt><label>Valor Promocional</label></dt> <dd><input type="text" name="PRO_VALPRO" value="<?php echo $this->data['PRO_VALPRO']?>" class="valor" /></dd>
        <dt><label>Valor Promocional até dia</label></dt> <dd><input type="text" name="PRO_DATPRO" value="<?php echo $this->data['PRO_DATPRO']?>" class="data" /></dd>
        <dt><label>Prazo de Entrega em dias</label></dt> <dd><input type="text" name="PRO_PZO" value="<?php echo $this->data['PRO_PZO']?>" class="numero" /></dd>
        <dt><label>Publicar Prazo de Entrega</label></dt> <dd><?php echo elemform::checkbox('PRO_STAPZO', '1', $this->data['PRO_STAPZO']); ?> Ativo</dd>
    </div>
    
    <div class="col">
        <dd><label>&nbsp;</label></dd>
        <dt><label>Destaque</label></dt> <dd><?php echo elemform::checkbox('PRO_STAPRO', '1', $this->data['PRO_STAPRO']); ?> Sim</dd>
        <dt><label>Segmento</label></dt> <dd> <?php echo elemform::select('CTS_ID', 'CTS_NOM', $this->data['CTS_ID'],'CTS_STA',1); ?> </dd> 
        <dt><label>Categoria</label></dt> <dd> <?php echo elemform::select('CAT_ID', 'CAT_NOM', $this->data['CAT_ID'],'CAT_STA',1); ?> </dd>
        <dt><label>1&deg; Grade de Tamanho</label></dt> <dd> <?php echo elemform::selectPdr('GRA_ID', 'GRA_ID', $this->data['GRA_ID'],'GRA_STA',1); ?> </dd> 
        <dt><label>2&deg; Grade de Tamanho</label></dt> <dd> <?php echo elemform::selectPdr('GRA_ID2', 'GRA_ID', $this->data['GRA_ID2'],'GRA_STA',null); ?> </dd> 
        <dt><label>Tamanhos</label></dt> <dd id="tamanhos"></dd> 
        <dt><label>Fornecedor</label></dt> <dd> <?php echo elemform::selectPdr('FOR_ID', 'FOR_NOM', $this->data['FOR_ID'],'FOR_STA',1); ?> </dd> 
        <dt><label>Material</label></dt> <dd> <?php echo elemform::selectPdr('MAT_ID', 'MAT_NOM', $this->data['MAT_ID'],'MAT_STA',1); ?> </dd> 
        <dt><label>Grade de Cor</label></dt> <dd> <?php echo elemform::selectPdr('GRC_ID', 'GRC_ID', $this->data['GRC_ID'],'GRC_STA',1); ?> </dd>
        <dt><label>Grade de Cor Detalhe</label></dt> <dd> <?php echo elemform::selectPdr('GCD_ID', 'GCD_NOM', $this->data['GCD_ID']); ?> </dd>
        
        
        <input type="submit" class="btn-button btn-ok" value="Cadastrar" id="submitbutton">
        <a class="btn-button btn-cancel" href="<?php echo $this->baseUrl($this->modulo.'/'.$this->controller); ?>">Cancelar</a>
        
    </div>   
    
    </form>
</div>
<script>
$(document).ready(function() {   
    dataPicker($('.data'));
});
</script>
<script src="<?php echo $this->urlbase;?>/public/media/js/jquery.jcarousel.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {   
    $('.slider').jcarousel({ auto: 4 });
});
</script>

<link rel="stylesheet" href="<?php echo $this->urlbase.'/public/media/js/multiupload/css/bootstrap.min.css'; ?>">
<link rel="stylesheet" href="<?php echo $this->urlbase.'/public/media/js/multiupload/css/font-awesome.css'; ?>">
<link rel="stylesheet" href="<?php echo $this->urlbase.'/public/media/js/multiupload/css/jquery.fileupload-ui.css'; ?>" />

<script src="<?php echo $this->urlbase.'/public/media/js/multiupload/'; ?>js/vendor/jquery.ui.widget.js"></script>
<script src="<?php echo $this->urlbase.'/public/media/js/multiupload/'; ?>js/jquery.iframe-transport.js"></script>
<script src="<?php echo $this->urlbase.'/public/media/js/multiupload/'; ?>js/jquery.fileupload.js"></script>
<script>
$(function () {
    'use strict';
    // Change this to the location of your server-side upload handler:
    var url = '<?php echo $this->urlbase.'/public/media/js/multiupload/server/php/'; ?>';
    $('#fileupload').fileupload({
        url: url,
        dataType: 'json',
        done: function (e, data) {
            $.each(data.result.files, function (index, file) {
                $('<p/>').text(file.name).appendTo('#files');
            });
        },
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progress .progress-bar').css(
                'width',
                progress + '%'
            );
            if(progress == 100)  if(confirm('Gostaria de atualizar as fotos?')){ window.location.reload(); }
            
        }
    }).prop('disabled', !$.support.fileInput)
        .parent().addClass($.support.fileInput ? undefined : 'disabled');
});
</script>

<script>
$(document).ready(function() {   
    $('.img').click(function(){
        if($(this).attr('select') == '1'){
            $(this).removeClass('select').removeAttr('select');
        }else{
            $('.img').removeClass('select').removeAttr('select');
            
            $(this).addClass('select').attr('select','1');
            $('.fot_pr').attr('src',$(this).attr('src').replace('_tb','_hl'));
        }
    });
    
    $('.ex-ft').click(function(){
        var count = 0;
        if(confirm('Deseja excluir a foto?'))
        $('.select').each(function() {    
            var el = $(this);
            count = 1;
            var src = el.attr('src'); 
            if(src.indexOf("?") >= 0){
                src = src.split("?");
                src = src[0];
            }
            $.get(URLBASE+'/'+CONTROL+'/delfoto', { src:src }, function(data){                  
                if(data.ok)
                {   
                    if(el.attr('src').replace('_tb','_hl') == $('.fot_pr').attr('src')){
                        $('.fot_pr').attr('src','');
                    }
                    //if(el.attr('src').replace() == )
                    el.remove();
                }   
            }, 'json');
        });
        if(count == 0) alert('selecione uma foto para excluir!');
    }); 
    
    <?php if($this->data['CAT_ID'] > 0) echo 'combocat('.$this->data['PRO_ID'].','.$this->data['CTS_ID'].');'; ?>
    <?php if($this->data['FOR_ID'] > 0 || $this->data['CAT_ID'] > 0) echo 'combofor('.$this->data['PRO_ID'].','.$this->data['CTS_ID'].','.$this->data['CAT_ID'].');'; ?>
    <?php if($this->data['GRA_ID'] > 0 || $this->data['CAT_ID'] > 0) echo 'combograd('.$this->data['PRO_ID'].','.$this->data['CTS_ID'].','.$this->data['CAT_ID'].');'; ?>
    <?php if($this->data['GRA_ID2'] > 0 || $this->data['CAT_ID'] > 0) echo 'combograd2('.$this->data['PRO_ID'].','.$this->data['CTS_ID'].','.$this->data['CAT_ID'].');'; ?>
    <?php if($this->data['GRA_ID'] > 0) echo 'setTimeout( function(){ combotam('.$this->data['PRO_ID'].','.$this->data['GRA_ID'].'); }, 1000);'; ?>
    <?php if($this->data['FOR_ID'] > 0 && $this->data['CAT_ID'] > 0) echo 'setTimeout( function(){ combomat('.$this->data['PRO_ID'].','.$this->data['FOR_ID'].','.$this->data['CAT_ID'].'); }, 500);';  ?>
    <?php if($this->data['GRC_ID'] > 0) echo 'setTimeout( function(){ combogradcor('.$this->data['PRO_ID'].','.$this->data['FOR_ID'].','.$this->data['MAT_ID'].','.$this->data['CTS_ID'].'); }, 2000);'; ?>
    <?php if($this->data['CAT_ID'] > 0) echo 'setTimeout( function(){ combogradcordet('.$this->data['PRO_ID'].','.$this->data['CTS_ID'].','.$this->data['CAT_ID'].'); }, 2000);'; ?>
    
});
</script>
